package com.bygf.curve;

import com.bygf.curve.panel.ChartPanel;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;

/**
 * 警戒线，此警戒线仅绘制水平方向的线条
 *
 * @author sunyupei
 */
public class WarnLine {

    //曲线渲染器
    private CurveRender render = new CurveRender();
    //警戒线名称
    private String name;
    //警戒线数值
    private double value;
    //使用纵坐标轴2标识
    private boolean usedY2Axis = false;
    //是否绘制警戒线名称标识
    private boolean nameVisible = true;
    //警戒线名称字体样式
    private Font nameFont = new Font("宋体", Font.PLAIN, 12);

    /**
     * 构造方法
     *
     * @param name 警戒线名称
     * @param value 警戒线数值
     * @param usedY2Axis 是否使用Y2坐标轴
     */
    public WarnLine(String name, double value, boolean usedY2Axis) {
        this.name = name;
        this.value = value;
        this.usedY2Axis = usedY2Axis;
    }

    /**
     * 警戒线绘制方法
     *
     * @param g
     * @param chartPanel
     */
    public void draw(Graphics2D g, ChartPanel chartPanel) {
        if (!render.isCurveVisible()) {
            return;
        }
        g.setColor(render.getColor());
        g.setStroke(render.getStroke());
        g.setFont(nameFont);
        double x1 = 0, x2 = chartPanel.getCurvePanel().getWidth();
        double y;
        if (usedY2Axis) {
            y = chartPanel.getY2Axis().valueToPix(value);
        } else {
            y = chartPanel.getYAxis().valueToPix(value);
        }
        Line2D line = new Line2D.Double(x1, y, x2, y);
        g.draw(line);
        if (nameVisible) {
            g.drawString(name, (float) x1, (float) y - 2);
        }
    }

    /**
     * @return the value
     */
    public double getValue() {
        return value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(double value) {
        this.value = value;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the bShowName
     */
    public boolean isNameVisible() {
        return nameVisible;
    }

    /**
     * @param nameVisible the nameVisible to set
     */
    public void setNameVisible(boolean nameVisible) {
        this.nameVisible = nameVisible;
    }

    /**
     * @return the nameFont
     */
    public Font getNameFont() {
        return nameFont;
    }

    /**
     * @param nameFont the nameFont to set
     */
    public void setNameFont(Font nameFont) {
        this.nameFont = nameFont;
    }

    /**
     * @return the render
     */
    public CurveRender getRender() {
        return render;
    }

    /**
     * @param render the render to set
     */
    public void setRender(CurveRender render) {
        this.render = render;
    }

    /**
     * @return the usedY2Axis
     */
    public boolean isUsedY2Axis() {
        return usedY2Axis;
    }

    /**
     * @param usedY2Axis the usedY2Axis to set
     */
    public void setUsedY2Axis(boolean usedY2Axis) {
        this.usedY2Axis = usedY2Axis;
    }
}
